import os
import oss2

# 填写你的Access Key ID和Access Key Secret
auth = oss2.Auth('LTAI5tBWSfGYWw9cveErF9iU', 'eUPnw9SrEgFpbxyZDBKfYckToZuAQN')
# 填写Bucket信息
bucket = oss2.Bucket(auth, 'https://oss-cn-beijing.aliyuncs.com', 'zddsc')

# 需要上传的本地目录路径
local_dir = 'test-as'
# OSS上的目录路径
oss_dir = 'test-as/aa'


# 上传目录
def upload_directory(local_dir, oss_dir):
    for root, dirs, files in os.walk(local_dir):
        for file in files:
            # 构造本地文件路径
            local_path = os.path.join(root, file)
            # 构造OSS文件路径
            oss_path = os.path.join(oss_dir, os.path.relpath(local_path, local_dir))
            # 上传文件
            bucket.put_object_from_file(oss_path, local_path)


upload_directory(local_dir, oss_dir)